create or replace package body package_gui as

PROCEDURE renderHead ( 
  title IN VARCHAR2 DEFAULT 'WebApplication BDL 2011',
  cssFileList IN package_gui_statics.arrayIntVarchar DEFAULT defaultparamlistvarchar2,
  javascriptFileList IN package_gui_statics.arrayIntVarchar DEFAULT defaultparamlistvarchar2
) IS
BEGIN
	htp.htmlOpen; 
	htp.headOpen;
  
  /** Print di tutti i file css e di tutte le librerie js utilizzate */
  /** In una seconda versione verranno introdotte anche i filtri sulle librerie usate */
  
  /** Dato che al momento non conosco bene le funzioni builtin di htp faccio il print diretto dell'html */
  htp.print('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
  htp.print('<meta name="language" content="it" />');
  htp.print('<!-- blueprint CSS framework -->');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/screen.css" media="screen, projection" />');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/print.css" media="print" />');
  htp.print('<!--[if lt IE 8]>');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/ie.css" media="screen, projection" />');
  htp.print('<![endif]-->');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/main.css" />');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/form.css" />');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/redmond/jquery-ui-1.8.11.custom.css" />');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/jquery.qtip.min.css" />');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/multiselect/ui.multiselect.css" />');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/multiselect/common.css" />');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/gridview/styles.css" />');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/pager.css" />');
  htp.print('<link rel="stylesheet" type="text/css" href="'|| package_gui_statics.serverHTTP ||'css/detailview/styles.css" />');
  
  IF cssFileList.COUNT > 0 THEN
    FOR keyString IN cssFileList.FIRST .. cssFileList.LAST
    LOOP
      htp.print('<link rel="stylesheet" type="text/css" href="'|| cssFileList(keyString) || '" />');
    END LOOP;
  END IF;
  
  htp.print('<script type="text/javascript" src="'|| package_gui_statics.serverHTTP ||'js/jquery-1.6.0.min.js"></script>');
  htp.print('<script type="text/javascript" src="'|| package_gui_statics.serverHTTP ||'js/jquery-ui-1.8.11.custom.min.js"></script>');
  htp.print('<script type="text/javascript" src="'|| package_gui_statics.serverHTTP ||'js/jquery.validate.min.js"></script>');
  htp.print('<script type="text/javascript" src="'|| package_gui_statics.serverHTTP ||'js/localization/messages_it.js"></script>');
  htp.print('<script type="text/javascript" src="'|| package_gui_statics.serverHTTP ||'js/jquery.qtip.min.js"></script>');
  htp.print('<script type="text/javascript" src="'|| package_gui_statics.serverHTTP ||'js/jquery.dynamicField-1.0.js"></script>');
  htp.print('<script type="text/javascript" src="'|| package_gui_statics.serverHTTP ||'js/plugins/localisation/jquery.localisation-min.js"></script>');
  htp.print('<script type="text/javascript" src="'|| package_gui_statics.serverHTTP ||'js/plugins/scrollTo/jquery.scrollTo-min.js"></script>');
  htp.print('<script type="text/javascript" src="'|| package_gui_statics.serverHTTP ||'js/ui.multiselect.js"></script>');
  
  IF javascriptFileList.COUNT > 0 THEN
    FOR keyString IN javascriptFileList.FIRST .. javascriptFileList.LAST
    LOOP
      htp.print('<script type="text/javascript" src="'|| javascriptFileList(keyString) ||'"></script>');
    END LOOP;
  END IF;
  
  htp.title( title );
  htp.headClose; 
  htp.bodyOpen;
  

END renderHead; 

PROCEDURE openPageBody( breadCrubs IN package_gui_statics.arrayVarcharVarchar DEFAULT defaultBreadCrumbsArray ) IS

arrayKey VARCHAR2(512);
sessionString VARCHAR2(512) := '';
BEGIN

  IF packageGuiSessionVariable IS NOT NULL THEN
    sessionString := '?private_session=' || packageGuiSessionVariable;
  END IF;

  /** Header */
  htp.print('<div class="container" id="page">');
  htp.print('<div id="header">');
  htp.print('<div id="logo">Basi di Dati Laboratorio 2011</div>');
  htp.print('</div><!-- header -->');
  
  /** Main menu con UL */
  htp.print('<div id="mainmenu">');
  htp.print('<ul id="mainmenu_ul">');
  htp.print('<li class="active"><a href="index.php?r=site/index'||sessionString||'">Home</a></li>');
  htp.print('<li><a href="index.php?r=site/login'||sessionString||'">Category 1</a></li>');
  htp.print('<li><a href="index.php?r=site/login'||sessionString||'">Category 2</a></li>');
  htp.print('<li><a href="index.php?r=site/login'||sessionString||'">Category 3</a></li>');
  htp.print('<li><a href="index.php?r=site/login'||sessionString||'">Category 4</a></li>');
  htp.print('<li><a href="index.php?r=site/login'||sessionString||'">Category 5</a></li>');
  htp.print('</ul>	');
  htp.print('</div><!-- mainmenu -->');
  
  /** Bread Crumbs*/
  htp.print('<div class="breadcrumbs"> ');
  arrayKey := breadCrubs.FIRST;
  WHILE arrayKey IS NOT NULL LOOP  
    IF breadCrubs(arrayKey) IS NOT NULL THEN
      htp.print( '<a href="' || breadCrubs(arrayKey) ||sessionString||  '">' || substr(arrayKey, 2) || '</a> &raquo;' );
    ELSE
      htp.print( '<span>' || substr(arrayKey, 2) || '</span>' );
    END IF;
    arrayKey := breadCrubs.NEXT( arrayKey );  
  END LOOP;
  /** L'ultima Bread Crubs andrebbe messa come <span>breadcrumbs 2</span> invece che come link attivo */
  htp.print('</div><!-- breadcrumbs --> ');

END openPageBody;

PROCEDURE closePageBody IS
BEGIN
  htp.print('</div>');
END closePageBody;

PROCEDURE openPageContainer IS
BEGIN
  htp.print('<div class="container">');
END openPageContainer;

PROCEDURE closePageContainer IS
BEGIN
  htp.print('</div>');
END closePageContainer;

PROCEDURE openContent IS
BEGIN		
  htp.print('<div class="span-19">');
  htp.print('<div id="content">');
END openContent;

PROCEDURE closeContent IS
BEGIN
  htp.print('</div><!-- content -->');
  htp.print('</div>');
END closeContent;

PROCEDURE openSidebar IS
BEGIN		
  htp.print('<!-- inizio colonna destra -->');
  htp.print('<div class="span-5 last">');
  htp.print('<div id="sidebar"> <!-- inizio sidebar -->');			 
END openSidebar;

PROCEDURE closeSidebar IS
BEGIN
  htp.print('</div><!-- fine sidebar --> ');
  htp.print('</div><!-- fine colonna destra -->');
END closeSidebar;

PROCEDURE renderUserMenu IS
BEGIN
  htp.print('<div class="portlet" id="user-menu-portlet">');
  htp.print('<div class="portlet-decoration">');
  htp.print('<div class="portlet-title">Menu Utente</div>');
  htp.print('</div>');
  htp.print('<div class="portlet-content">');
  htp.print('<ul class="operations" id="yw3">');
  IF getSession IS NOT NULL AND getSessionInformation('username') IS NOT NULL AND getSessionInformation('password') IS NOT NULL AND getSessionInformation('role') IS NOT NULL THEN
    htp.print('<li><a href="http://oracle3.cli.di.unipi.it/apex/RICCI.login.processLogout">Logout</a></li>');
  ELSE
    htp.print('<li><a href="http://oracle3.cli.di.unipi.it/apex/RICCI.login.renderLogin">Login</a></li>');
  END IF;
  htp.print('</ul>');
  htp.print('</div>');
  htp.print('</div>');					
END renderUserMenu;

PROCEDURE renderOperationsMenu ( operationLinks IN package_gui_statics.arrayVarcharVarchar DEFAULT defaultOperationMenuLinkArray ) IS
arrayKey VARCHAR2(50);
sessionString VARCHAR2(512);
BEGIN

  IF packageGuiSessionVariable IS NOT NULL THEN
    sessionString := '?private_session=' || packageGuiSessionVariable;
  END IF;

  htp.print('<div class="portlet" id="operations-menu-portlet">');
  htp.print('<div class="portlet-decoration">');
  htp.print('<div class="portlet-title">Menu Operazioni</div>');
  htp.print('</div>');
  htp.print('<div class="portlet-content">');
  htp.print('<ul class="operations" id="operations-portlet-ul">');
  arrayKey := operationLinks.FIRST;
  WHILE arrayKey IS NOT NULL LOOP  
    htp.print('<li><a href="' || operationLinks(arrayKey) ||sessionString ||  '">'|| arrayKey ||'</a></li>');
    arrayKey := operationLinks.NEXT( arrayKey );  
  END LOOP;
  htp.print('</ul>');
  htp.print('</div>');
  htp.print('</div>');					
END renderOperationsMenu;

PROCEDURE renderFooter IS
BEGIN
  htp.print('<div id="footer">');		
  htp.print('Copyright &copy; 2011 by BDL GUI Group.<br/>');	
  htp.print('All Rights Reserved.<br/>');	
  htp.print('<a href="http://projects.cli.di.unipi.it/bdl2011/" rel="external">Project Home</a> | <a href="http://www.designfuture.it/bdl/sql_developer/docs/" rel="external">JavaDoc</a>');	
  htp.print('</div><!-- footer -->');	
  htp.print('</div><!-- page -->');	
  htp.print('</body>');	
  htp.print('</html>');
END renderFooter; 

/* PROTOTYPE DECLARATION */
PROCEDURE printValidationRule(
  validationRule IN package_gui_statics.ruleDefinitionType DEFAULT NULL
);

PROCEDURE initjQTip IS
elemName VARCHAR2(512);
BEGIN
    htp.print('
    
       // qtips
      $(":input").qtip({
          style: {
            tip: true,
            classes: "ui-tooltip-cream"
          },
          position: {
            at: "right center",
            my: "left center"
          },
          show: {
            event: "focus"
          },
          hide: {
            event: "unfocus"
          }
        }
      );
      
			$.localise("ui-multiselect", {language: "it", path: "'||package_gui_statics.serverHTTP||'js/locale/"});
			$(".multiselect").multiselect();

      
    
      //form validation
      var myForm = $("form:first");
      
      
 
     myForm.validate({
           errorClass: "errormessage",
           onkeyup: false,
           errorClass: "error",
           validClass: "valid",
           /*showErrors: function(errorMap, errorList) {
            if ( this.numberOfInvalids() > 0 ) {
              $("#summary-error").html("Your form contains "
                                           + this.numberOfInvalids() 
                                           + " errors, see details below.");
              $("#summary-error").show();
              this.defaultShowErrors();
            } else {
              $("#summary-error").hide();
            }
          }*/
           rules: {
           ');
           elemName := arrayRules.FIRST;
           WHILE elemName IS NOT NULL LOOP
              htp.print(elemName||': {');
              printValidationRule(arrayRules(elemName));
              htp.print('},');
              elemName := arrayRules.NEXT(elemName);
           END LOOP;
           /*htp.print('},
           
           messages: {
           ');
           elemName := arrayRules.FIRST;
           WHILE elemName IS NOT NULL LOOP
              htp.print(elemName||': {');
              printValidationRuleMessages(arrayRules(elemName));
              htp.print('},');
              elemName := arrayRules.NEXT(elemName);
           END LOOP;
          */
          htp.print('},
           
           errorPlacement: function(error, element)
           {
              // Set positioning based on the elements position in the form
              var elem = $(element),
                 title = $(element).attr("title"),
                 corners = ["left center", "right center"],
                 flipIt = false;
              // Check we have a valid error message
              if(!error.is(":empty")) {
                  $(element).attr("title", "");
                 // Apply the tooltip only if it isnt valid
                 elem.filter(":not(.valid)").qtip({
                    overwrite: true,
                    content: error,
                    position: {
                       my: corners[ flipIt ? 0 : 1 ],
                       at: corners[ flipIt ? 1 : 0 ],
                       viewport: $(window)
                    },
                    show: {
                       event: false,
                       ready: true
                    },
                    hide: false,
                    style: {
                       classes: "ui-tooltip-red" // Make it red... the classic error colour!
                    }
                 })
   
                 // If we have a tooltip on this element already, just update its content
                 .qtip("option", "content.text", error);
                 $(element).attr("title", title);
              }
   
              // If the error is empty, remove the qTip
              else { 
                  elem.qtip({
                    overwrite: true,
                    content: title,
                    style: {
                      tip: true,
                      classes: "ui-tooltip-cream"
                    },
                    position: {
                      at: "right center",
                      my: "left center"
                    },
                    show: {
                      event: "focus"
                    },
                    hide: {
                      event: "unfocus"
                    }
                  }
                );
              }
              
           },
           success: $.noop, // Odd workaround for errorPlacement not firing!
     });
    
 
    
    ');
END initjQTip;

PROCEDURE openjQuerySnippet IS
BEGIN
  htp.print('<script type="text/javascript">');
	htp.print('$(function(){');		
  initjQTip;
END openjQuerySnippet;

PROCEDURE closejQuerySnippet IS
BEGIN
  htp.print('	});');
  htp.print('</script>');		
END closejQuerySnippet;

/* GESTIONE DEI FORM */

PROCEDURE renderStatusMessage (
  divClass IN VARCHAR2 DEFAULT NULL,
  message IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  htp.print('<div class="'||divClass||'">');
  htp.print(message);
  htp.print('</div>');
END renderStatusMessage;

PROCEDURE renderSuccessMessage(
  message IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  renderStatusMessage('flash-success', message);
END renderSuccessMessage;

PROCEDURE renderErrorMessage(
  message IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  renderStatusMessage('flash-error', message);
END renderErrorMessage;



PROCEDURE printValidationRule(
  validationRule IN package_gui_statics.ruleDefinitionType DEFAULT NULL
) IS 
BEGIN
  IF validationRule.is_required THEN htp.print('required: true,'); ELSE htp.print('required: false,'); END IF;
  IF validationRule.minlength IS NOT NULL THEN htp.print('minlength: '||to_char(validationRule.minlength)||','); END IF;
  IF validationRule.maxlength IS NOT NULL THEN htp.print('maxlength: '||to_char(validationRule.maxlength)||','); END IF;
  IF validationRule.rangelength IS NOT NULL THEN htp.print('rangelength: '||validationRule.rangelength||','); END IF;
  IF validationRule.min_val IS NOT NULL THEN htp.print('min: '||to_char(validationRule.min_val)||','); END IF;
  IF validationRule.max_val IS NOT NULL THEN htp.print('max: '||to_char(validationRule.max_val)||','); END IF;
  IF validationRule.range_val IS NOT NULL THEN htp.print('range: '||validationRule.range_val||','); END IF;
  IF validationRule.email THEN htp.print('email: true,'); ELSE htp.print('email: false,'); END IF;
  IF validationRule.url THEN htp.print('url: true,'); ELSE htp.print('url: false,'); END IF;
  IF validationRule.date_rule THEN htp.print('date: true,'); ELSE htp.print('date: false,'); END IF;
  IF validationRule.only_number THEN htp.print('number: true,'); ELSE htp.print('number: false,'); END IF;
  IF validationRule.only_digit THEN htp.print('digits: true,'); ELSE htp.print('digits: false,'); END IF;
END printValidationRule;

FUNCTION initRuleDefinition ( 
   is_required       BOOLEAN DEFAULT TRUE,
   minlength        BINARY_INTEGER DEFAULT NULL,
   maxlength        BINARY_INTEGER DEFAULT NULL,
   rangelength      VARCHAR2 DEFAULT NULL,
   min_val           BINARY_INTEGER DEFAULT NULL,
   max_val           BINARY_INTEGER DEFAULT NULL,
   range_val         VARCHAR2 DEFAULT NULL,
   email            BOOLEAN DEFAULT FALSE,
   url              BOOLEAN DEFAULT FALSE,
   date_rule         BOOLEAN DEFAULT FALSE,
   only_number       BOOLEAN DEFAULT FALSE,
   only_digit        BOOLEAN DEFAULT FALSE
) RETURN package_gui_statics.ruleDefinitionType IS
  localRule package_gui_statics.ruleDefinitionType;
BEGIN
  localRule.is_required := is_required;
  localRule.minlength := minlength;
  localRule.maxlength := maxlength;
  localRule.rangelength := rangelength;
  localRule.min_val := min_val;
  localRule.max_val := max_val;
  localRule.range_val := range_val;
  localRule.email := email;
  localRule.url := url;
  localRule.date_rule := date_rule;
  localRule.only_number := only_number;
  localRule.only_digit := only_digit;
  RETURN localRule;
END initRuleDefinition;

/** Tipo ruleMessageType utilizzato per associare messaggi di errore personalizzati alle relative validazioni */
FUNCTION initRuleMessage ( 
   msg_is_required      VARCHAR2 DEFAULT NULL,
   msg_minlength        VARCHAR2 DEFAULT NULL,
   msg_maxlength        VARCHAR2 DEFAULT NULL,
   msg_rangelength      VARCHAR2 DEFAULT NULL,
   msg_min_val          VARCHAR2 DEFAULT NULL,
   msg_max_val          VARCHAR2 DEFAULT NULL,
   msg_range_val        VARCHAR2 DEFAULT NULL,
   msg_email            VARCHAR2 DEFAULT NULL,
   msg_url              VARCHAR2 DEFAULT NULL,
   msg_date_rule        VARCHAR2 DEFAULT NULL,
   msg_only_number      VARCHAR2 DEFAULT NULL,
   msg_only_digit       VARCHAR2 DEFAULT NULL
) RETURN package_gui_statics.ruleMessageType IS
  localRuleMsg package_gui_statics.ruleMessageType;
BEGIN
  localRuleMsg.msg_is_required := msg_is_required;
  localRuleMsg.msg_minlength := msg_minlength;
  localRuleMsg.msg_maxlength := msg_maxlength;
  localRuleMsg.msg_rangelength := msg_rangelength;
  localRuleMsg.msg_min_val := msg_min_val;
  localRuleMsg.msg_max_val := msg_max_val;
  localRuleMsg.msg_range_val := msg_range_val;
  localRuleMsg.msg_email := msg_email;
  localRuleMsg.msg_url := msg_url;
  localRuleMsg.msg_date_rule := msg_date_rule;
  localRuleMsg.msg_only_number := msg_only_number;
  localRuleMsg.msg_only_digit := msg_only_digit;
  RETURN localRuleMsg;
END initRuleMessage;

PROCEDURE printValidationRuleMessages(
  vrMSG IN package_gui_statics.ruleMessageType DEFAULT NULL
) IS 
BEGIN
  IF vrMSG.msg_is_required IS NOT NULL THEN htp.print('required: '||vrMSG.msg_is_required||','); END IF;
  IF vrMSG.msg_minlength IS NOT NULL THEN htp.print('minlength: '||vrMSG.msg_minlength||','); END IF;
  IF vrMSG.msg_maxlength IS NOT NULL THEN htp.print('maxlength: '||vrMSG.msg_maxlength||','); END IF;
  IF vrMSG.msg_rangelength IS NOT NULL THEN htp.print('rangelength: '||vrMSG.msg_rangelength||','); END IF;
  IF vrMSG.msg_min_val IS NOT NULL THEN htp.print('min: '||vrMSG.msg_min_val||','); END IF;
  IF vrMSG.msg_max_val IS NOT NULL THEN htp.print('max: '||vrMSG.msg_max_val||','); END IF;
  IF vrMSG.msg_range_val IS NOT NULL THEN htp.print('range: '||vrMSG.msg_range_val||','); END IF;
  IF vrMSG.msg_email IS NOT NULL THEN htp.print('email: '||vrMSG.msg_email||','); END IF;
  IF vrMSG.msg_url IS NOT NULL THEN htp.print('url: '||vrMSG.msg_url||','); END IF;
  IF vrMSG.msg_date_rule IS NOT NULL THEN htp.print('date: '||vrMSG.msg_date_rule||','); END IF;
  IF vrMSG.msg_url IS NOT NULL THEN htp.print('url: '||vrMSG.msg_url||','); END IF;
  IF vrMSG.msg_only_number IS NOT NULL THEN htp.print('number: '||vrMSG.msg_only_number||','); END IF;
  IF vrMSG.msg_only_digit IS NOT NULL THEN htp.print('digits: '||vrMSG.msg_only_digit||','); END IF;
END printValidationRuleMessages;

PROCEDURE addValidationRule(
  elemName IN VARCHAR2 DEFAULT NULL,
  validationRule IN package_gui_statics.ruleDefinitionType DEFAULT NULL,
  validationRuleMessage IN package_gui_statics.ruleMessageType DEFAULT NULL
) IS 
BEGIN
arrayRules(elemName) := validationRule;
arrayRulesMessage(elemName) := validationRuleMessage;
END addValidationRule;

/* DECLARE PRIVATE PROCEDURES */

PROCEDURE renderInputField(
  isRequired IN BOOLEAN DEFAULT FALSE,
  inputType IN VARCHAR2 DEFAULT 'text',
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemClass IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemSize IN BINARY_INTEGER DEFAULT 25,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemTip IN VARCHAR2 DEFAULT NULL,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
);

/* IMPLEMENTATION OF PROCEDURES */


PROCEDURE renderLabel (
  fieldId IN VARCHAR2 DEFAULT NULL,
  labelClass IN VARCHAR2 DEFAULT 'required',
  labelValue IN VARCHAR2 DEFAULT NULL
) IS
labelText VARCHAR2(512) := labelValue;
BEGIN
  IF labelClass LIKE 'required' 
  THEN 
    labelText := labelText || ' <span class="required">*</span>';
  END IF;
  IF labelValue IS NOT NULL THEN 
    htp.print('<label for="'|| fieldId ||'" class="'|| labelClass ||'">'|| labelText ||'</label>');
  END IF;
END renderLabel;

PROCEDURE openInput IS
BEGIN
  htp.print('<div class="row">');		  
END openInput;

PROCEDURE closeInput IS
BEGIN
  htp.print('</div>');		  
END closeInput;

PROCEDURE openForm ( 
  formName IN VARCHAR2 DEFAULT NULL,
  formId IN VARCHAR2 DEFAULT NULL,
  formAction IN VARCHAR2 DEFAULT NULL,
  formMethod IN VARCHAR2 DEFAULT NULL,
  formEncType IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  htp.print('<div class="form">');		
  htp.print('<form name="' || formName || '" id="' || formId || '" action="' || formAction || '" method="' || formMethod|| '" enctype="'||formEncType||'">');		
  htp.print('<p class="note">I campi contrassegnati da <span class="required">*</span> sono obbligatori </p>');		
END openForm;

PROCEDURE closeForm IS
BEGIN
  htp.print('</form>');		  
  htp.print('</div><!-- form -->');
END closeForm;

PROCEDURE renderSubmitButton( title IN VARCHAR2 DEFAULT 'Invia' ) IS
BEGIN
  htp.print('<div class="row buttons">');
	htp.print('<input type="submit" name="submit_button_form" value="'|| title ||'" />');
  htp.print('</div>');
END renderSubmitButton;

PROCEDURE renderTextField (
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemSize IN BINARY_INTEGER DEFAULT 25,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemTip IN VARCHAR2 DEFAULT NULL,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS
BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  renderInputField(isRequired, 'text', elemLabel, '', elemName, elemId, elemValue, elemSize, elemMaxLength, elemTip, elemJavaScriptEvents );
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
END renderTextField;

PROCEDURE renderTextAreaField(
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemRows IN VARCHAR2 DEFAULT 10,
  elemCols IN BINARY_INTEGER DEFAULT 35,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemTip IN VARCHAR2 DEFAULT NULL,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS
elemClassInside VARCHAR2(20) := '';
BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  IF elemLabel IS NOT NULL THEN 
    IF isRequired THEN renderLabel( elemId, 'required', elemLabel ); ELSE renderLabel( elemId, '', elemLabel ); END IF;
  END IF;
  IF elemTip IS NOT NULL 
  THEN
    elemClassInside := 'qtipped';
  END IF;
  htp.print('<textarea rows="'||elemRows||'" cols="'||elemCols||'" class="'|| elemClassInside ||'" maxlength="'|| elemMaxLength||'" name="'|| elemName ||'" id="'|| elemId ||'" title="'|| elemTip ||'" value="'|| elemValue ||'" '||elemJavaScriptEvents||' />');	
  htp.print('</textarea>');
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
END renderTextAreaField;

PROCEDURE renderFileField (
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemSize IN BINARY_INTEGER DEFAULT 25,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemTip IN VARCHAR2 DEFAULT NULL,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS
BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  renderInputField(isRequired, 'file', elemLabel, '', elemName, elemId, elemValue, elemSize, elemMaxLength, elemTip, elemJavaScriptEvents );
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
END renderFileField;

PROCEDURE renderButton(
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS
BEGIN
  htp.print('<div class="row buttons">');
	htp.print('<input type="button" id="'||elemId||'" name="'||elemName||'" value="'|| elemValue ||'" '||elemJavaScriptEvents||'/>');
  htp.print('</div>');
END renderButton;

PROCEDURE renderDropDownField(
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemSelected IN VARCHAR2 DEFAULT NULL,
  elemParamList IN package_gui_statics.arrayVarcharVarchar DEFAULT defaultParamList,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS
optionValue VARCHAR2(512);
BEGIN
  htp.print('<select name="'|| elemName ||'" id="'|| elemId ||'" '||elemJavaScriptEvents||' >');
  optionValue := elemParamList.FIRST;
  WHILE optionValue IS NOT NULL LOOP  
    IF elemSelected IS NOT NULL AND optionValue = elemSelected THEN
      htp.print( '<option value="'|| optionValue ||'" selected="selected">'|| elemParamList(optionValue) ||'</option>' );
    ELSE
      htp.print( '<option value="'|| optionValue ||'">'|| elemParamList(optionValue) ||'</option>' );
    END IF;
    optionValue := elemParamList.NEXT( optionValue );  
  END LOOP;
  htp.print('</select>');
END renderDropDownField;

PROCEDURE renderDropDown(
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemSelected IN VARCHAR2 DEFAULT NULL,
  elemParamList IN package_gui_statics.arrayVarcharVarchar DEFAULT defaultParamList,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS
BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  IF isRequired THEN renderLabel( elemId, 'required', elemLabel ); ELSE renderLabel( elemId, '', elemLabel ); END IF;
  renderDropDownField(elemName, elemId, elemSelected, elemParamList, elemJavaScriptEvents);  
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
END renderDropDown;

FUNCTION in_array(
  toSearch IN VARCHAR2 DEFAULT NULL,
  arrayList IN package_gui_statics.arrayIntVarchar DEFAULT defaultParamListVarchar2
) RETURN BOOLEAN IS
BEGIN
  FOR keyString IN arrayList.FIRST .. arrayList.LAST
  LOOP
    IF toSearch = arrayList(keyString) THEN RETURN TRUE; END IF;
  END LOOP;
  RETURN FALSE;
END in_array;

PROCEDURE rendeMultiDropDownField(
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemSelectedList IN package_gui_statics.arrayIntVarchar DEFAULT defaultParamListVarchar2,
  elemParamList IN package_gui_statics.arrayVarcharVarchar DEFAULT defaultParamList,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS
optionValue VARCHAR2(512);
BEGIN
  htp.print('<select  multiple="multiple" class="multiselect" name="'|| elemName ||'" id="'|| elemId ||'" '||elemJavaScriptEvents||' >');
  optionValue := elemParamList.FIRST;
  WHILE optionValue IS NOT NULL LOOP  
    IF elemSelectedList.COUNT > 0 AND in_array(optionValue, elemSelectedList) THEN
      htp.print( '<option value="'|| optionValue ||'" selected="selected">'|| elemParamList(optionValue) ||'</option>' );
    ELSE
      htp.print( '<option value="'|| optionValue ||'">'|| elemParamList(optionValue) ||'</option>' );
    END IF;
    optionValue := elemParamList.NEXT( optionValue );  
  END LOOP;
  htp.print('</select>');
END rendeMultiDropDownField;

procedure renderMultiDropDown(
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemSelectedList IN package_gui_statics.arrayIntVarchar DEFAULT defaultParamListVarchar2,
  elemParamList IN package_gui_statics.arrayVarcharVarchar DEFAULT defaultParamList,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
)  IS
BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  IF isRequired THEN renderLabel( elemId, 'required', elemLabel ); ELSE renderLabel( elemId, '', elemLabel ); END IF;
  rendeMultiDropDownField(elemName, elemId, elemSelectedList, elemParamList, elemJavaScriptEvents);  
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
END renderMultiDropDown;

PROCEDURE renderPasswordField(
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemSize IN BINARY_INTEGER DEFAULT 25,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemTip IN VARCHAR2 DEFAULT NULL,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS
BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  renderInputField( isRequired, 'password', elemLabel, '', elemName, elemId, elemValue, elemSize, elemMaxLength, elemTip, elemJavaScriptEvents );
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
END renderPasswordField;

PROCEDURE renderHiddenField(
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemSize IN BINARY_INTEGER DEFAULT 25,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS
BEGIN
  renderInputField(FALSE, 'hidden', '', '', elemName, elemId, elemValue, elemSize, elemMaxLength, '', elemJavaScriptEvents );
END renderHiddenField;

PROCEDURE renderCheckBox(
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemTip IN VARCHAR2 DEFAULT NULL,
  elemChecked IN VARCHAR2 DEFAULT NULL,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS

elemClass VARCHAR2(20) := '';
elemCheckedString VARCHAR2(20) := '';

BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  IF elemLabel IS NOT NULL THEN 
    IF isRequired THEN renderLabel( elemId, 'required', elemLabel ); ELSE renderLabel( elemId, '', elemLabel ); END IF;
  END IF;
  IF elemTip IS NOT NULL 
  THEN
    elemClass := 'qtipped';
  END IF;
  IF elemChecked IS NOT NULL THEN
    elemCheckedString := 'checked="checked"';
  END IF;
  htp.print('<input class="'|| elemClass ||'" name="'|| elemName ||'" id="'|| elemId ||'" type="checkbox" title="'|| elemTip ||'" value="'|| elemValue ||'" '|| elemCheckedString ||' '||elemJavaScriptEvents||' />');	
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
END renderCheckBox;

PROCEDURE renderRadioButton(
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemTip IN VARCHAR2 DEFAULT NULL,
  elemChecked IN VARCHAR2 DEFAULT NULL,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS

elemClass VARCHAR2(20) := '';
elemCheckedString VARCHAR2(20) := '';

BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  IF elemLabel IS NOT NULL THEN 
    IF isRequired THEN renderLabel( elemId, 'required', elemLabel ); ELSE renderLabel( elemId, '', elemLabel ); END IF;
  END IF;
  IF elemTip IS NOT NULL 
  THEN
    elemClass := 'qtipped';
  END IF;
  IF elemChecked IS NOT NULL THEN
    elemCheckedString := 'checked="checked"';
  END IF;
  htp.print('<input class="'|| elemClass ||'" name="'|| elemName ||'" id="'|| elemId ||'" type="radio" title="'|| elemTip ||'" value="'|| elemValue ||'" '|| elemCheckedString ||' '||elemJavaScriptEvents||' />');	
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
END renderRadioButton;

PROCEDURE renderRadioButtonList (
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemTip IN VARCHAR2 DEFAULT NULL,
  elemParamList IN package_gui_statics.arrayVarcharVarchar DEFAULT defaultParamList,
  elemChecked IN VARCHAR2 DEFAULT NULL,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS
radioButtonValue VARCHAR2(512);
elemClass VARCHAR2(20) := '';
elemCheckedString VARCHAR2(20) := '';
BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  IF elemLabel IS NOT NULL THEN 
    IF isRequired THEN renderLabel( elemId, 'required', elemLabel ); ELSE renderLabel( elemId, '', elemLabel ); END IF;
  END IF;
  radioButtonValue := elemParamList.FIRST;
  WHILE radioButtonValue IS NOT NULL LOOP  
    IF elemChecked IS NOT NULL AND elemChecked = radioButtonValue THEN
      elemCheckedString := 'checked="checked"';
    ELSE
      elemCheckedString := '';
    END IF;
    IF elemTip IS NOT NULL 
    THEN
      elemClass := 'qtipped';
    END IF;
    htp.print( elemParamList(radioButtonValue) || ' <input class="'|| elemClass ||'" name="'|| elemName ||'" type="radio" title="'|| elemTip ||'" value="'|| radioButtonValue ||'" '|| elemCheckedString ||' '||elemJavaScriptEvents||' />');	
    
    radioButtonValue := elemParamList.NEXT( radioButtonValue );  
  END LOOP;
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
END renderRadioButtonList;

PROCEDURE renderInputField(
  isRequired IN BOOLEAN DEFAULT FALSE,
  inputType IN VARCHAR2 DEFAULT 'text',
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemClass IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemSize IN BINARY_INTEGER DEFAULT 25,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemTip IN VARCHAR2 DEFAULT NULL,
  elemJavaScriptEvents IN VARCHAR DEFAULT ''
) IS

elemClassInside VARCHAR2(20) := '';

BEGIN
  elemClassInside := elemClass;
  IF elemLabel IS NOT NULL THEN 
    IF isRequired THEN renderLabel( elemId, 'required', elemLabel ); ELSE renderLabel( elemId, '', elemLabel ); END IF;
  END IF;
  IF elemTip IS NOT NULL 
  THEN
    elemClassInside := 'qtipped';
  END IF;
  htp.print('<input class="'|| elemClassInside ||'" size="'|| elemSize ||'" maxlength="'|| elemMaxLength||'" name="'|| elemName ||'" id="'|| elemId ||'" type="'|| inputType ||'" title="'|| elemTip ||'" value="'|| elemValue ||'" '||elemJavaScriptEvents||' />');	
END renderInputField;

PROCEDURE renderDatePicker(
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemSize IN BINARY_INTEGER DEFAULT 25,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemTip IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  renderInputField(isRequired, 'text', elemLabel, '', elemName, elemId, elemValue, elemSize, elemMaxLength, elemTip );
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
  htp.print('<script type="text/javascript">');
  htp.print('  //datepicker');
	htp.print('	$( "#'|| elemId ||'" ).datepicker({');
	htp.print('		showOn: "button",');
  htp.print('		dateFormat: "dd/mm/yy",');
	htp.print('		buttonImage: "'|| package_gui_statics.serverHTTP ||'images/icons/date.png",');
	htp.print('		buttonImageOnly: true');
	htp.print('	});');
  htp.print('</script>');
  
END renderDatePicker;

PROCEDURE renderTimePicker(
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValueHour IN VARCHAR2 DEFAULT NULL,
  elemValueMinute IN VARCHAR2 DEFAULT NULL,
  elemTip IN VARCHAR2 DEFAULT NULL
) IS
/** Variabile privata per l'elenco delle ore */
timePickerHour package_gui_statics.arrayVarcharVarchar;
/** Variabile privata per l'elenco dei minuti */
timePickerMinute package_gui_statics.arrayVarcharVarchar;

BEGIN
  for i in 0..23 loop
      IF i < 10 THEN 
        timePickerHour('0'||to_char(i)) := '0'||to_char(i);
        timePickerMinute('0'||to_char(i)) := '0'||to_char(i);
      ELSE
        timePickerHour(to_char(i)) := to_char(i);
        timePickerMinute(to_char(i)) := to_char(i);
      END IF;
  end loop;
  for i in 24..59 loop
        timePickerMinute(to_char(i)) := to_char(i);
  end loop;
  
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  IF isRequired THEN renderLabel( elemId, 'required', elemLabel ); ELSE renderLabel( elemId, '', elemLabel ); END IF;
  renderDropDownField(elemName||'_hour', elemId||'_hour', elemValueHour, timePickerHour);  
  renderDropDownField(elemName||'_minute', elemId||'_minute', elemValueMinute, timePickerMinute);  
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
  
END renderTimePicker;

PROCEDURE renderRangeDatePicker(
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValueFrom IN VARCHAR2 DEFAULT NULL,
  elemValueTo IN VARCHAR2 DEFAULT NULL,
  elemSize IN BINARY_INTEGER DEFAULT 25,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemTip IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  renderInputField(isRequired, 'text', elemLabel, '', elemName || '_from', elemId || '_from', elemValueFrom, elemSize, elemMaxLength, '' );
  renderInputField(FALSE, 'text', '', '', elemName || '_to', elemId || '_to', elemValueTo, elemSize, elemMaxLength, '' );
  IF elemLabel IS NOT NULL THEN  closeInput; END IF;
  
  htp.print('<script type="text/javascript">');
  htp.print('var jsVar'|| elemId ||' = $( "#'|| elemId ||'_from, #'|| elemId ||'_to" ).datepicker({');
	htp.print('		defaultDate: "+1w",');
	htp.print('		changeMonth: true,');
  htp.print('		dateFormat: "dd/mm/yy",');
	htp.print('   numberOfMonths: 3,');
	htp.print('		onSelect: function( selectedDate ) {');
	htp.print('			var option = this.id == "'|| elemId ||'_from" ? "minDate" : "maxDate",');
	htp.print('				instance = $( this ).data( "datepicker" ),');
	htp.print('				date = $.datepicker.parseDate(');
	htp.print('					instance.settings.dateFormat ||');
	htp.print('					$.datepicker._defaults.dateFormat,');
	htp.print('					selectedDate, instance.settings );');
	htp.print('			jsVar'|| elemId ||'.not( this ).datepicker( "option", option, date );');
	htp.print('		}');
  htp.print('});');
  htp.print('</script>');
  
END renderRangeDatePicker;

PROCEDURE renderAjaxTextField(
  isRequired IN BOOLEAN DEFAULT FALSE,
  ajaxSource IN VARCHAR2 DEFAULT NULL,
  fillHidden IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemSize IN BINARY_INTEGER DEFAULT 25,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemTip IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  IF elemLabel IS NOT NULL THEN openInput; END IF;
  renderInputField(isRequired, 'text', elemLabel, '', elemName, elemId, elemValue, elemSize, elemMaxLength, elemTip );
  IF fillHidden THEN
    renderHiddenField( elemName || '_hidden', elemId || '_hidden', '', elemSize, 255 );
  END IF;
  IF elemLabel IS NOT NULL THEN closeInput; END IF;
  htp.print('<script type="text/javascript">');
  htp.print('$( "#'|| elemId ||'" ).autocomplete({');
	htp.print('		source: "'|| ajaxSource ||'",');
	htp.print('		minLength: 2,');
	htp.print('		select: function( event, ui ) {');
  IF fillHidden THEN
    htp.print('		  $( "#' || elemId || '_hidden" ).val(ui.item.id);');
  END IF;
	htp.print('		}');
  htp.print('});');
  htp.print('</script>');
  
END renderAjaxTextField;

PROCEDURE initDynamicFieldList IS
BEGIN
  openInput;
END initDynamicFieldList;

PROCEDURE endDynamicFieldList (
  formId IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  closeInput;
  htp.print('<script type="text/javascript">');
  htp.print('//Dynamic form fields');
  htp.print('$("#'|| formId ||' #removable-'|| elemId ||'-container-1").dynamicField();');
  htp.print('</script>');
END endDynamicFieldList;

/*
PROCEDURE renderDynamicAjaxTextField(
  ajaxSource IN VARCHAR2 DEFAULT NULL,
  fillHidden IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemSize IN BINARY_INTEGER DEFAULT 25,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemTip IN VARCHAR2 DEFAULT NULL,
  elemIndex IN BINARY_INTEGER DEFAULT 1,
  paramList IN package_gui_statics.arrayIntVarchar DEFAULT defaultParamListVarchar2
) IS
label VARCHAR2(512) := '';
BEGIN
  IF elemIndex = paramList.FIRST OR paramList.COUNT = 0 THEN
    label := elemLabel;
  END IF;
  renderInputField('text', label, 'textInput removable', elemName, elemId||'-'||to_char(elemIndex), elemValue, elemSize, elemMaxLength, elemTip );  
  IF fillHidden THEN
    renderHiddenField( elemName || '_hidden', elemId || '_hidden', '', elemSize, 255 );
  END IF;
  htp.print('<div class="addictional-javascript" style="visibility: hidden">');
  htp.print('<script type="text/javascript">');
  htp.print('$( "#'|| elemId||'-'||to_char(elemIndex) ||'" ).autocomplete({');
	htp.print('		source: "'|| ajaxSource ||'",');
	htp.print('		minLength: 2,');
	htp.print('		select: function( event, ui ) {');
  IF fillHidden THEN
    htp.print('		  $( "#' || elemId||'-'||to_char(elemIndex) || '_hidden" ).val(ui.item.id);');
  END IF;
	htp.print('		}');
  htp.print('});');
  htp.print('</script>');
  htp.print('</div>');
  
END renderDynamicAjaxTextField;
*/

PROCEDURE openDynamicTextFieldList (
  elemId IN VARCHAR2 DEFAULT NULL,
  elemIndex IN BINARY_INTEGER DEFAULT 1
) IS
BEGIN
  htp.print('<div id="removable-'|| elemId ||'-container-'|| to_char(elemIndex) ||'" class="removable-'|| elemId ||'-row">');
END openDynamicTextFieldList;

PROCEDURE closeDynamicTextFieldList (
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemIndex IN BINARY_INTEGER DEFAULT 1,
  paramList IN package_gui_statics.arrayIntVarchar DEFAULT defaultParamListVarchar2
) IS
BEGIN
  IF elemIndex = paramList.FIRST OR paramList.COUNT = 0 THEN -- E' la prima occorrenza
    htp.print('<img src="'|| package_gui_statics.serverHTTP ||'images/spacer.gif" width="16" height="16" alt="" title="Rimuovi questo elemento" class="" />');
  ELSE 
    htp.print('<img width="16" height="16" class="remove-field-trigger" title="Rimuovi questo elemento" alt="" src="'|| package_gui_statics.serverHTTP ||'images/icons/delete.png">');
  END IF;
  
  htp.print('</div>');
  IF elemIndex = paramList.LAST OR paramList.COUNT = 0 THEN
  htp.print('<div id="add-'|| elemId ||'-container" class="add-field-container">');
  htp.print('<span class="add-field-trigger">');
  htp.print('<img src="'|| package_gui_statics.serverHTTP ||'images/icons/add.png" alt="" title="Aggiungi elemento" />');
  htp.print('Aggiungi '|| elemLabel ||'');
  htp.print('</span>');
  htp.print('</div>');
  END IF;
END closeDynamicTextFieldList;

PROCEDURE renderDynamicTextField(
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemValue IN VARCHAR2 DEFAULT NULL,
  elemSize IN BINARY_INTEGER DEFAULT 25,
  elemMaxLength IN BINARY_INTEGER DEFAULT 255,
  elemTip IN VARCHAR2 DEFAULT NULL,
  elemIndex IN BINARY_INTEGER DEFAULT 1,
  paramList IN package_gui_statics.arrayIntVarchar DEFAULT defaultParamListVarchar2
) IS
label VARCHAR2(512) := '';
BEGIN
  IF elemIndex = paramList.FIRST OR paramList.COUNT = 0 THEN
    label := elemLabel;
  END IF;
  renderInputField(isRequired, 'text', label, 'textInput removable', elemName, elemId||'-'||to_char(elemIndex), elemValue, elemSize, elemMaxLength, elemTip );  
END renderDynamicTextField;

PROCEDURE openDynamicDropDownFieldList (
  elemId IN VARCHAR2 DEFAULT NULL,
  elemIndex IN BINARY_INTEGER DEFAULT 1
) IS
BEGIN
  htp.print('<div id="removable-'|| elemId ||'-container-'|| to_char(elemIndex) ||'" class="removable-'|| elemId ||'-row">');
END openDynamicDropDownFieldList;

PROCEDURE closeDynamicDropDownFieldList (
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemIndex IN BINARY_INTEGER DEFAULT NULL,
  paramList IN package_gui_statics.arrayIntVarchar DEFAULT defaultParamListVarchar2
) IS
BEGIN
  IF elemIndex = paramList.FIRST OR paramList.COUNT = 0 THEN -- E' la prima occorrenza
    htp.print('<img src="'|| package_gui_statics.serverHTTP ||'images/spacer.gif" width="16" height="16" alt="" title="Rimuovi questo elemento" class="" />');
  ELSE 
    htp.print('<img width="16" height="16" class="remove-field-trigger" title="Rimuovi questo elemento" alt="" src="'|| package_gui_statics.serverHTTP ||'images/icons/delete.png">');
  END IF;
  
  htp.print('</div>');
  IF elemIndex = paramList.LAST OR paramList.COUNT = 0 THEN
  htp.print('<div id="add-'|| elemId ||'-container" class="add-field-container">');
  htp.print('<span class="add-field-trigger">');
  htp.print('<img src="'|| package_gui_statics.serverHTTP ||'images/icons/add.png" alt="" title="Aggiungi elemento" />');
  htp.print('Aggiungi '|| elemLabel ||'');
  htp.print('</span>');
  htp.print('</div>');
  END IF;
END closeDynamicDropDownFieldList;

PROCEDURE renderDynamicDropDownField(
  isRequired IN BOOLEAN DEFAULT FALSE,
  elemLabel IN VARCHAR2 DEFAULT NULL,
  elemName IN VARCHAR2 DEFAULT NULL,
  elemId IN VARCHAR2 DEFAULT NULL,
  elemSelected IN VARCHAR2 DEFAULT NULL,
  elemParamList IN package_gui_statics.arrayVarcharVarchar DEFAULT defaultParamList,
  elemIndex IN BINARY_INTEGER DEFAULT 1,
  paramList IN package_gui_statics.arrayIntVarchar DEFAULT defaultParamListVarchar2
) IS
optionValue VARCHAR2(512);
BEGIN
  IF (elemIndex = paramList.FIRST OR paramList.COUNT = 0) AND elemLabel != '' THEN
    IF isRequired THEN renderLabel( elemId, 'required', elemLabel ); ELSE renderLabel( elemId, '', elemLabel ); END IF;
  END IF;
  
  htp.print('<select name="'|| elemName ||'" id="'|| elemId||'-'||to_char(elemIndex) ||'" class="textInput removable">');
  optionValue := elemParamList.FIRST;
  WHILE optionValue IS NOT NULL LOOP  
    IF elemSelected IS NOT NULL AND optionValue = elemSelected THEN
      htp.print( '<option value="'|| optionValue ||'" selected="selected">'|| elemParamList(optionValue) ||'</option>' );
    ELSE
      htp.print( '<option value="'|| optionValue ||'">'|| elemParamList(optionValue) ||'</option>' );
    END IF;
    optionValue := elemParamList.NEXT( optionValue );  
  END LOOP;
  htp.print('</select>');
END renderDynamicDropDownField;

/* MANAGE PAGE PROCEDURES */
PROCEDURE openManageTable(
  manageFormId IN VARCHAR2 DEFAULT 'manage-form',
  addictionalParameters IN VARCHAR2 DEFAULT '',
  deleteFormAction IN VARCHAR2 DEFAULT '',
  lowerBoundRecord IN BINARY_INTEGER DEFAULT 1,
  upperBoundRecord IN BINARY_INTEGER DEFAULT 1,
  recordCount IN BINARY_INTEGER DEFAULT 1,
  columnNameArray IN package_gui_statics.arrayIntVarchar DEFAULT defaultparamlistvarchar2,
  hasDeletePermission IN BOOLEAN DEFAULT TRUE,
  hasActions IN BOOLEAN DEFAULT TRUE
) IS
tempArray package_gui_statics.arrayIntVarchar;
BEGIN
  htp.print('<form name="'||manageFormId||'" id="'||manageFormId||'" action="' || deleteFormAction || '?' || addictionalParameters || '" method="GET">');		
  htp.print('<div id="canale-grid" class="grid-view">');
  htp.print('<div class="summary">');  
  
  IF hasDeletePermission THEN 
    htp.print('<div class="summary-left">');
    htp.print('<a class="delete-button" title="Elimina elementi selezionati" href="#"><img src="'|| package_gui_statics.serverHTTP ||'images/gridview/delete.png" alt="Delete" /></a>');
    htp.print(' Elimina tutti gli elementi selezionati');
    htp.print('</div>');
  END IF;
  htp.print('<div class="summary-right">');
  htp.print('Displaying '||lowerBoundRecord||'-'||upperBoundRecord||' of '||recordCount||' result(s).</div>');
  htp.print('</div>');
  htp.print('<table id="manage-table" class="items">');
  htp.print('<thead>');
  htp.print('<tr>');
  IF hasDeletePermission THEN 
    htp.print('<th class="button-column"></th>');
  END IF;
  FOR i IN columnNameArray.FIRST .. columnNameArray.LAST
  LOOP
       htp.print('<th>'||columnNameArray(i)||'</th>');
  END LOOP;
  IF hasActions THEN
    htp.print('<th class="button-column">Azioni</th>');
  END IF;
  htp.print('</tr>');
  htp.print('</thead>');
END openManageTable;

PROCEDURE closeManageTable(
  manageFormId IN VARCHAR2 DEFAULT 'manage-form',
  addictionalParameters IN VARCHAR2 DEFAULT '',
  pagerLink IN VARCHAR2 DEFAULT NULL,
  pagerCurrent IN BINARY_INTEGER DEFAULT 1,
  pagerLast IN BINARY_INTEGER DEFAULT 1,
  pagerParamName IN VARCHAR2 DEFAULT 'page'
) IS 
prevLimit BINARY_INTEGER := pagerCurrent - 5;
nextLimit BINARY_INTEGER := pagerCurrent + 5;
BEGIN
  htp.print('</tbody>');
  htp.print('</table>');
  htp.print('<div class="pager">Vai alla pagina: <ul id="yw1" class="yiiPager">');
  IF pagerCurrent = 1 THEN
    htp.print('<li class="first hidden"><a href="'||pagerLink||'?'||pagerParamName||'=1&'||addictionalParameters||'">&lt;&lt; Prima</a></li>');
    htp.print('<li class="previous hidden"><a href="'||pagerLink||'?'||pagerParamName||'=1&'||addictionalParameters||'">&lt; Precedente</a></li>');
  ELSE 
    htp.print('<li class="first"><a href="'||pagerLink||'?'||pagerParamName||'=1&'||addictionalParameters||'">&lt;&lt; Prima</a></li>');
    htp.print('<li class="previous"><a href="'||pagerLink||'?'||pagerParamName||'='||to_char(pagerCurrent-1)||'&'||addictionalParameters||'">&lt; Precedente</a></li>');
  END IF;
  
  IF prevLimit < 1 THEN
    prevLimit := 1;
  END IF;
  IF nextLimit > pagerLast THEN
    nextLimit := pagerLast;
  END IF;
  
  FOR i IN prevLimit .. nextLimit
  LOOP
      IF pagerCurrent = i THEN
        htp.print('<li class="page selected"><a href="'||pagerLink||'?'||pagerParamName||'='||to_char(i)||'&'||addictionalParameters||'">'||to_char(i)||'</a></li>');
      ELSE
        htp.print('<li class="page"><a href="'||pagerLink||'?'||pagerParamName||'='||to_char(i)||'&'||addictionalParameters||'">'||to_char(i)||'</a></li>');
      END IF;
  END LOOP;
  
  IF pagerCurrent = pagerLast THEN
    htp.print('<li class="next hidden"><a href="'||pagerLink||'?'||pagerParamName||'='||to_char(pagerLast)||'&'||addictionalParameters||'">Successiva &gt;</a></li>');
    htp.print('<li class="last hidden"><a href="'||pagerLink||'?'||pagerParamName||'='||to_char(pagerLast)||'&'||addictionalParameters||'">Ultima &gt;&gt;</a></li>');
  ELSE
    htp.print('<li class="next"><a href="'||pagerLink||'?'||pagerParamName||'='||to_char(pagerCurrent+1)||'&'||addictionalParameters||'">Successiva &gt;</a></li>');
    htp.print('<li class="last"><a href="'||pagerLink||'?'||pagerParamName||'='||to_char(pagerLast)||'&'||addictionalParameters||'">Ultima &gt;&gt;</a></li>');
  END IF;
  htp.print('</ul></div></div>');
  htp.print('
  <script type="text/javascript">  
  jQuery("#'||manageFormId||' a.delete").live("click",function() {
    if(!confirm("Sei sicuro di voler cancellare questo elemento?")) return false;
    else return true;
  });
  jQuery("#'||manageFormId||' a.delete-button").live("click",function() {
    if(!confirm("Sei sicuro di voler cancellare gli elementi selezioni?")) return false;
    else jQuery("#'||manageFormId||'").submit();
  });
  function getUrlVars( urlString )
  {
      
      var vars = [], hash;
      var hashes = urlString.slice(urlString.indexOf("?") + 1).split("&");
      for(var i = 0; i < hashes.length; i++)
      {
          hash = hashes[i].split("=");
          //vars.push(hash[0]);
          vars[hash[0]] = hash[1];
      }
      if ( hashes.length > 0 ) return vars;
      else return null;
  }
  $("#'||manageFormId||'").submit(function(){ //listen for submit event
      
      if ( "'||substr(addictionalParameters, -1)||'" == "&" )
        var params = getUrlVars( "?'||substr(addictionalParameters, 1, LENGTH(addictionalParameters)-1)||'");
      else
        var params = getUrlVars( "?'||addictionalParameters||'");
      
      if ( params != null ) {
        for(var i in params) {
          try
          {
              $("<input />").attr("type", "hidden")
                .attr("name", i)
                .attr("value", params[i])
                .appendTo("#'||manageFormId||'");
          } catch(err) {
            continue;
          }
        }
      }
      return true;
  });

  </script>
  ');
  
  htp.print('</form>');
END closeManageTable;

PROCEDURE openManageTableRow (
  elemId IN VARCHAR2 DEFAULT NULL,
  hasDeletePermission IN BOOLEAN DEFAULT TRUE
) IS
BEGIN
  htp.print('<tr class="odd">');
  IF hasDeletePermission THEN
    htp.print('<td class="button-column">');
    htp.print('<input type="checkbox" name="id" value="'||elemId||'" />');
    htp.print('</td>');
  END IF;
  
END openManageTableRow;

PROCEDURE closeManageTableRow (
  viewLink IN VARCHAR2 DEFAULT NULL,
  updateLink IN VARCHAR2 DEFAULT NULL,
  deleteLink IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  IF viewLink IS NOT NULL OR updateLink IS NOT NULL OR deleteLink IS NOT NULL THEN
    htp.print('<td class="button-column">');
      IF viewLink IS NOT NULL THEN 
        htp.print('<a class="view"title="Visualizza" href="'||viewLink||'"><img src="'|| package_gui_statics.serverHTTP ||'images/gridview/view.png" alt="View" /></a>');
      END IF;
      IF updateLink IS NOT NULL THEN
        htp.print('<a class="update" title="Modifica" href="'||updateLink||'"><img src="'|| package_gui_statics.serverHTTP ||'images/gridview/update.png" alt="Update" /></a>');
      END IF;
      IF deleteLink IS NOT NULL THEN
        htp.print('<a class="delete" title="Elimina" href="'||deleteLink||'"><img src="'|| package_gui_statics.serverHTTP ||'images/gridview/delete.png" alt="Delete" /></a>');
      END IF;
    htp.print('</td>');
  END IF;
  htp.print('</tr>');
  
END closeManageTableRow;

PROCEDURE initCloseManageTableRow IS
BEGIN
  htp.print('<td class="button-column">');
END initCloseManageTableRow;

PROCEDURE renderManageTableRowButton (
  buttonImage IN VARCHAR2 DEFAULT NULL,
  buttonLabel IN VARCHAR2 DEFAULT NULL,
  buttonUrl IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  htp.print('<a class="view" title="'||buttonLabel||'" href="'||buttonUrl||'"><img src="'|| buttonImage ||'" alt="'||buttonLabel||'" /></a>');
END renderManageTableRowButton;

PROCEDURE renderDefManageTableButtons (
  viewLink IN VARCHAR2 DEFAULT NULL,
  updateLink IN VARCHAR2 DEFAULT NULL,
  deleteLink IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  IF viewLink IS NOT NULL THEN 
      htp.print('<a class="view"title="Visualizza" href="'||viewLink||'"><img src="'|| package_gui_statics.serverHTTP ||'images/gridview/view.png" alt="View" /></a>');
    END IF;
		IF updateLink IS NOT NULL THEN
      htp.print('<a class="update" title="Modifica" href="'||updateLink||'"><img src="'|| package_gui_statics.serverHTTP ||'images/gridview/update.png" alt="Update" /></a>');
    END IF;
		IF deleteLink IS NOT NULL THEN
      htp.print('<a class="delete" title="Elimina" href="'||deleteLink||'"><img src="'|| package_gui_statics.serverHTTP ||'images/gridview/delete.png" alt="Delete" /></a>');
    END IF;
END renderDefManageTableButtons;

PROCEDURE finishCloseManageTableRow IS
BEGIN
  htp.print('</td>');
  htp.print('</tr>');
END finishCloseManageTableRow;

PROCEDURE renderManageTableRow(
  elemValue IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
  htp.print('<td>'||elemValue||'</td>');
END renderManageTableRow;

-- PROCEDURE DEDICATE AL MANAGEMENT DELLA VARIABILE DI SESSIONE

FUNCTION explode (
  p_seperator IN VARCHAR2, 
  p_string IN VARCHAR2
) RETURN package_gui_statics.arrayIntVarchar IS
  l_string LONG := p_string || p_seperator;
  l_data package_gui_statics.arrayIntVarchar;
  n NUMBER;
BEGIN
   LOOP
      EXIT WHEN l_string IS NULL;
      n := INSTR (l_string, p_seperator);
      --l_data.EXTEND;
      l_data (l_data.COUNT) := LTRIM (RTRIM (SUBSTR (l_string, 1, n - 1)));
      l_string := SUBSTR (l_string, n + 1);
   END LOOP;

   RETURN l_data;
END explode;

FUNCTION implode (
  p_seperator IN VARCHAR2,
  p_data package_gui_statics.arrayIntVarchar
) RETURN VARCHAR2 IS
  localString VARCHAR2(512) := '';
BEGIN
  FOR i IN p_data.FIRST .. p_data.LAST
  LOOP
    localString := localString || p_data(i);
    IF i != p_data.LAST THEN localString := localString || p_seperator; END IF;
  END LOOP;
  RETURN localString;
END implode;

PROCEDURE newSession IS
newPackageGuiSessionCouples package_gui_statics.arrayVarcharVarchar;
BEGIN
  packageGuiSessionVariable := '';
  packageGuiSessionCouples := newPackageGuiSessionCouples;
END newSession;

PROCEDURE setSession(
  sessionValue IN VARCHAR2 DEFAULT ''
) IS
sessionExplode package_gui_statics.arrayIntVarchar;
keyValueCouple package_gui_statics.arrayIntVarchar;
BEGIN
  newSession;
  packageGuiSessionVariable := sessionValue;
  sessionExplode := explode( package_gui_statics.sessionCoupleSeparator, packageGuiSessionVariable);
  FOR i IN sessionExplode.FIRST .. sessionExplode.LAST
  LOOP
    keyValueCouple := explode( package_gui_statics.sessionKeyValueSeparator, sessionExplode(i) );
    -- controllo aggiuntivo, devono essere 2 elementi key=>value
    IF keyValueCouple.COUNT = 2 THEN
      packageGuiSessionCouples(keyValueCouple(keyValueCouple.FIRST)) := keyValueCouple(keyValueCouple.LAST);
    END IF;
  END LOOP;

END setSession;

PROCEDURE printSession IS
BEGIN
  FOR i IN packageGuiSessionCouples.FIRST .. packageGuiSessionCouples.LAST
  LOOP
    htp.print( i || ': ' || packageGuiSessionCouples(i) ||'<br/>' );
  END LOOP;
END printSession;

FUNCTION getSession RETURN VARCHAR2 IS
BEGIN
  RETURN packageGuiSessionVariable;
END getSession;

FUNCTION getSessionInformation(
 sessionInformationKey IN VARCHAR2 DEFAULT NULL
) RETURN VARCHAR2 IS
BEGIN
  RETURN packageGuiSessionCouples(sessionInformationKey);
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    RETURN ''; -- Quando si cerca di accedere a un informazione non presente si ritorna stringa vuota!
END getSessionInformation;

PROCEDURE setSessionInformation(
  sessionInformationKey IN VARCHAR2 DEFAULT NULL,
  sessionInformationValue IN VARCHAR2 DEFAULT NULL
) IS
BEGIN
   packageGuiSessionCouples(sessionInformationKey) := sessionInformationValue;
  packageGuiSessionVariable := packageGuiSessionVariable || package_gui_statics.sessionCoupleSeparator || sessionInformationKey || package_gui_statics.sessionKeyValueSeparator || sessionInformationValue; 
END setSessionInformation;

PROCEDURE renderHiddenFieldSession IS
BEGIN
  renderInputField(FALSE, 'hidden', '', '', 'private_session', 'private_session', getSession, 512, 512, '' );
END renderHiddenFieldSession;


-------- PROCEDURE DEDICATE AL MANAGEMENT DELLA VIEW DELLE INFORMAZIONI
PROCEDURE openViewTable IS
BEGIN
  htp.print('<table class="detail-view">');
END openViewTable;

PROCEDURE closeViewTable IS
BEGIN
  htp.print('</table>');
END closeViewTable;

PROCEDURE renderViewTableRow (
  keyString IN VARCHAR2 DEFAULT NULL,
  valueString IN VARCHAR2 DEFAULT NULL,
  rowCSSClass IN VARCHAR2 DEFAULT NULL
) IS
BEGIN 
  htp.print('<tr class="'||rowCSSClass||'"><th>'||keyString||'</th><td>'||valueString||'</td></tr>');
END renderViewTableRow;

PROCEDURE renderViewTable(
  paramList IN package_gui_statics.arrayVarcharVarchar DEFAULT defaultParamList
) IS 
  counter BINARY_INTEGER := 1;
  trClass VARCHAR2(512) := 'odd';
BEGIN
  htp.print('<table class="detail-view">');
  FOR field IN paramList.FIRST .. paramList.LAST
  LOOP
    IF counter MOD 2 = 0 THEN trClass := 'even'; ELSE trClass := 'odd'; END IF;
    htp.print('<tr class="'||trClass||'"><th>'||field||'</th><td>'||paramList(field)||'</td></tr>');
    counter := counter + 1;
  END LOOP;
  htp.print('</table>');
END renderViewTable;

------------------ PROCEDURE LOGIN

FUNCTION processLogin( 
  usernameParam IN VARCHAR2 DEFAULT NULL,
  passwordParam IN VARCHAR2 DEFAULT NULL
) RETURN VARCHAR2 IS
countRecord NUMBER := 0;
BEGIN
  --faccio le query per vedere se sono presenti utenti
  newSession;
  
  SELECT COUNT(1) INTO countRecord FROM dipendenti 
  JOIN magazzinieri ON dipendenti.IDDipendente = magazzinieri.IDMagazziniere
  WHERE LOWER(dipendenti.username) = LOWER(usernameParam) AND dipendenti.password = passwordParam;
  IF countRecord > 0 THEN
    setSessionInformation('username', usernameParam);
    setSessionInformation('password', passwordParam);
    setSessionInformation('role', package_gui_statics.ROLE_MAG);
    RETURN getSession;
  END IF;
  
  SELECT COUNT(1) INTO countRecord FROM dipendenti 
  JOIN amministratori ON dipendenti.IDDipendente = amministratori.IDAmministratore
  WHERE LOWER(dipendenti.username) = LOWER(usernameParam) AND dipendenti.password = passwordParam;
  IF countRecord > 0 THEN
    setSessionInformation('username', usernameParam);
    setSessionInformation('password', passwordParam);
    setSessionInformation('role', package_gui_statics.ROLE_SYS);
    RETURN getSession;
  END IF;
  
  
  SELECT COUNT(1) INTO countRecord FROM dipendenti 
  JOIN operatori ON dipendenti.IDDipendente = operatori.IDOperatore
  WHERE LOWER(dipendenti.username) = LOWER(usernameParam) AND dipendenti.password = passwordParam;
  IF countRecord > 0 THEN
    setSessionInformation('username', usernameParam);
    setSessionInformation('password', passwordParam);
    setSessionInformation('role', package_gui_statics.ROLE_OP);
    RETURN getSession;
  END IF;
  RETURN NULL;
END processLogin;

PROCEDURE processLogout IS
BEGIN
  newSession;
END processLogout;

END package_gui;
